<?php
namespace app\mapi\model;
use think\Model;

/**
 * 商品分类模型类
 * @author  黄明杰 vx:HMJ125855
 * @version 20190201
 */
class MallClassModel extends Model
{

    protected $name = 'MallClass';

    /**
     * 数据所有方法
     * @param   Array   $Where  查询条件
     * @param   String  $Field  查询字段
     * @param   Srting  $Order  查询排序
     * @return  Array
     */
    public function mAll($Where = [], $Field = '*', $Order = 'class_id ASC'){
        $Where['class_state'] = 1;
        $Where['class_del'] = 1;

        return $this->field($Field)->where($Where)->order($Order)->select();
    }

    /**
     * 数据排序方法
     * @param   Array   $Class  操作数组
     * @return  Array
     */
    public static function mTree($Class, $Line = '┗━', $Pid = 0, $Level = 0, $Left = 50){
        $Array = [];

        foreach($Class as $v){
            if($v['class_pid'] == $Pid){
                $v['class_level'] = $Level + 1;
                $v['class_left'] = $Left + 0;
                $v['class_line'] = str_repeat($Line, $Level);

                $Array[] = $v;
                $Array = array_merge($Array, self::mTree($Class, $Line, $v['class_id'], $Level + 1 , $Left + 20));
            }
        }

        return $Array;
    }

}